﻿using System.Text;
using Shop.RemoteModel;
using Shop.RemoteModel.ActivityDiscount.Model;
using WeDonekRpc.Helper;

namespace Shop.Collect.Linq
{
    internal static class DiscountLinq
    {

        public static string GetDiscountShow (this DiscountSet set)
        {
            StringBuilder str = new StringBuilder();
            if (set.Threshold == DiscountThreshold.无门槛)
            {
                set.Items.ForEach(c =>
                {
                    str.AppendFormat("{2}无门槛{0}：{1}。\n", c.Mode.ToString(), c.GiveName, c.IsFreeMail ? "(包邮)" : string.Empty);
                });
            }
            else if (set.Threshold == DiscountThreshold.每满减促销)
            {
                set.Items.ForEach(c =>
                {
                    if (c.ReduceTotalPrice.HasValue)
                    {
                        str.AppendFormat("{3}每满{0}元减:{1}元，{2}元封顶。\n", c.ThresholdPrice.Value, c.ReducePrice.Value, c.ReduceTotalPrice.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else
                    {
                        str.AppendFormat("{3}每满{0}元减:{1}元。\n", c.ThresholdPrice.Value, c.ReducePrice.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                });
            }
            else if (set.Threshold == DiscountThreshold.满件促销)
            {
                set.Items.ForEach(c =>
                {
                    if (c.Mode == DiscountContent.减金额)
                    {
                        str.AppendFormat("{2}满{0}件，减{1}元。\n", c.ThresholdNum.Value, c.ReducePrice.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.打折)
                    {
                        str.AppendFormat("{2}满{0}件，打{1}折。\n", c.ThresholdNum.Value, c.DiscountRatio.Value / 10, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.最低价商品享)
                    {
                        str.AppendFormat("{2}满{0}件，最低价商品享{1}元。\n", c.ThresholdNum.Value, c.DiscountPrice.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.减件)
                    {
                        str.AppendFormat("{2}满{0}件减{1}件。\n", c.ThresholdNum.Value, c.ReduceNum.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else
                    {
                        str.AppendFormat("满{0}件包邮。\n", c.ThresholdNum.Value);
                    }
                });
            }
            else if (set.Threshold == DiscountThreshold.满减促销)
            {
                set.Items.ForEach(c =>
                {
                    if (c.Mode == DiscountContent.送优惠卷 || c.Mode == DiscountContent.送赠品)
                    {
                        str.AppendFormat("{3}满{0}元{1}：{2}。\n", c.ThresholdPrice.Value, c.Mode.ToString(), c.GiveName, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.任选)
                    {
                        str.AppendFormat("{2}满{0}元任选：{1}件。\n", c.ThresholdPrice.Value, c.GiveNum.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.减金额)
                    {
                        str.AppendFormat("{2}满{0}元减{1}元。\n", c.ThresholdPrice.Value, c.ReducePrice.Value, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else if (c.Mode == DiscountContent.加多少元送赠品)
                    {
                        str.AppendFormat("{3}满{0}元加{1}元送赠品：{2}。\n", c.ThresholdPrice.Value, c.AddPrice.Value, c.GiveName, c.IsFreeMail ? "(包邮)" : string.Empty);
                    }
                    else
                    {
                        str.AppendFormat("满{0}元包邮。\n", c.ThresholdPrice.Value);
                    }
                });
            }
            else
            {
                return string.Empty;
            }
            str.Remove(str.Length - 1, 1);
            return str.ToString();
        }
    }
}
